package com.site.util;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.site.util.base.action.BaseAction;


public class WelcomeAction  extends BaseAction {

	private static final long serialVersionUID = -3466438193761883287L;

	protected Log logger=LogFactory.getLog(this.getClass());
	/*
	 * 欢迎页面CODE_NAME
	 */
	private static final String WECOME_PAGE_LIST="WECOME_PAGE_LIST";
	
	/*
	 * 欢迎页面key,放入request中
	 */
	private static final String ECOM_WELCOME_PAGE="ECOM_WELCOME_PAGE";
	
	/*
	 * 默认首页
	 */
	private static final String DEFAULT_PAGE="login.jsp";
	
	/**
	 * 根据域名，从code读取欢迎页面名称 
	 */
	public String execute()
	{
		//用户ip
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		
		// 获取Ip所在地信息
		//IPSeeker ipSeeker=IPSeeker.getInstance(request.getRealPath("/dat"));

		String host=request.getHeader("Host");
		//String welcomePage=CodeMapDBUtil.getCodeValueByKey(WECOME_PAGE_LIST, host.toLowerCase(), request);
		String welcomePage=null;
		//logger.info("欢迎光临："+host+" "+ipSeeker.getCountry(ip)+" "+ipSeeker.getArea(ip)+",IP:"+ip);
		
		if(!StringUtils.isEmpty(welcomePage))
			request.setAttribute(ECOM_WELCOME_PAGE, welcomePage);
		else
			request.setAttribute(ECOM_WELCOME_PAGE, DEFAULT_PAGE);
		return SUCCESS;
	}
	
}
